// 芯片数量M, 业务配置数量N,
// A业务占用2.5G, B业务占用10G ,问最后一个配置在那个芯片编号上
const readline = require("readline");
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});
let m, n; // m表示芯片数量
let initArr = [];
rl.on("line", (line) => {
    if (m === undefined) {
        [m, n] = line.trim().split(/\s+/).map(Number)
    } else {
        initArr = line.trim().split(/\s+/)
        getResult(m, n, initArr)
        // clear
        m = n = undefined
        initArr.length = 0
    }
})
function  getResult(m, n, initArr) {
    // A 占用 2.5 G, B占用10G
    let dp = new Array(m + 1).fill(10)
    let ans = []
    for (const k in initArr) {
        const char = initArr[k]
        let num = 2.5
        char !== "A" ?  num = 10 : ""
        let flag = true
        for (let i = 1; i <= m; i++) {
            if(dp[i] >= num ) {
                flag = false
                dp[i] -= num
                if(Number(k) === initArr.length - 1) {
                    ans = [i, char,  dp[i]]
                }
                break
            }
        }
        if(flag) {
            console.log("0 0")
            return
        }
    }

    let temp = 1
    if(ans[1] === "A") {
        switch (ans[2]) {
            case 0:
                temp = 4
                break;
            case 2.5:
                temp = 3
                break;
            case 5:
                temp = 2
                break;
            case 7.5:
                temp = 1
                break;
        }
    }
    console.log(`${ans[0]} ${temp}`)

}